<template>
  <div class="main-content">
    <el-form ref="form" :model="form" label-position="right" label-width="120px" :rules="dataFormRules" class="pt40">
      <el-row style="margin-top: -18px;">
        <el-form-item label="分销员:" prop="distributorSet">
          <el-input  @input="form.distributorSet=form.distributorSet.replace(/[^\d.]/g,'')"  v-model="form.distributorSet" maxlength="3" style="width:300px">
            <template slot="append">%</template>
          </el-input>
        </el-form-item>
      </el-row>
<!--      <el-row style="margin-top: 7px;">-->
<!--        <el-form-item label="代理:" prop="agentSet">-->
<!--          <el-input @input="form.agentSet=form.agentSet.replace(/[^\d.]/g,'')" v-model="form.agentSet" style="width:300px">-->
<!--            <template slot="append">%</template>-->
<!--          </el-input>-->
<!--        </el-form-item>-->
<!--      </el-row>-->
<!--      <el-row style="margin-top: 7px;">-->
<!--        <el-form-item label="代理下级:" prop="agentSubordinateSet">-->
<!--          <el-input @input="form.agentSubordinateSet=form.agentSubordinateSet.replace(/[^\d.]/g,'')" maxlength="3" v-model="form.agentSubordinateSet"  style="width:300px">-->
<!--            <template slot="append">%</template>-->
<!--          </el-input>-->
<!--        </el-form-item>-->
<!--      </el-row>-->
<!--      <el-row style="margin-top: 7px;">-->
<!--        <el-form-item label="分销商品:" prop="product">-->
<!--          <el-input @input="form.product=form.product.replace(/[^\d.]/g,'')" maxlength="3" v-model="form.product"  style="width:300px">-->
<!--            <template slot="append">%</template>-->
<!--          </el-input>-->
<!--        </el-form-item>-->
<!--      </el-row>-->
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        ids: '',
        values: [],
        form: {
          distributorSet: "0",
          agentSet: "",
          agentSubordinateSet: "",
          product: "",
        },
        dataFormRules: {
          distributorSet: [
            {required: true, message: "请输入分销员佣金", trigger: "blur"},
            {min: 0, max: 3, message: "长度最多输入三位", trigger: "blur"},
          ],
          agentSet: [{required: true, message: "请输入代理佣金", trigger: "blur"}],
          agentSubordinateSet: [{required: true, message: "请输入代理下级佣金", trigger: "blur"}],
          product: [{required: true, message: "请输入分享商品佣金", trigger: "blur"}],
        }
      }

    },
    methods: {
      //查询方法
      querInfo() {
        let this_ = this
        this_.utils.request.getMemDistributionCommissionSet({}, function (res) {
          if (res.code == '0000' && res.data.length > 0) {
            res.data.forEach(item=>{
              if(item.commissionType==1){
                this_.form.distributorSet=item.commissionRate
              }else if(item.commissionType==2){
                this_.form.agentSet=item.commissionRate
              }else if(item.commissionType==3){
                this_.form.agentSubordinateSet=item.commissionRate
              }else if(item.commissionType==4){
                this_.form.product=item.commissionRate
              }
            })

          }
        })
      },
      //编辑数据
      onSubmit() {
        let this_ = this
        this_.$refs.form.validate(valid => {
          if (valid) {
            this_.$confirm("确认提交吗？", "提示", {}).then(() => {
              let params={}
              let mCommissionRequestList=new Array();
              let obj1={};
              obj1.commissionType=1
              obj1.commissionRate=this_.form.distributorSet
              mCommissionRequestList.push(obj1)
              let obj2={};
              obj2.commissionType=2
              obj2.commissionRate=this_.form.agentSet
              mCommissionRequestList.push(obj2)
              let obj3={};
              obj3.commissionType=3
              obj3.commissionRate=this_.form.agentSubordinateSet
              mCommissionRequestList.push(obj3)
              let obj4={};
              obj4.commissionType=4
              obj4.commissionRate=this_.form.product
              mCommissionRequestList.push(obj4)
              params.mCommissionRequestList=mCommissionRequestList
              this.utils.request.saveMemDistributionCommissionSet(params, res => {
                if (res.code == "0000") {
                  this_.$message({message: "操作成功", type: "success"})
                } else {
                  this_.$message({message: "操作失败", type: 'error'});
                }
              })
            });
          }
        });
      },
    },
    mounted() {
      this.querInfo()
    }
  }
</script>

<style scoped lang='scss'>
  .main-content {
    width: 100%;
    text-align: center;
  }

  .pt40 {
    padding-top: 40px;
  }
</style>
